import collections
from datetime import datetime

import sys

sys.path.append("../")  # noqa
from config import col_okr
import typer

app = typer.Typer()

Department = collections.namedtuple('Department', 'label target, order')

constraint_dept = {
    "62b945cd9aebef53937fecc0": Department("创新战略研究院", 1100, 1),
    "62b945cd9aebef53937fecc1": Department("中国科普研究所", 2500, 2),
    "62b945cd9aebef53937fecc2": Department("学会服务中心", 6000, 3),
    "62b945cd9aebef53937fecc4": Department("中国科技馆", 5000, 4),
    "62b945cd9aebef53937fecc5": Department("青少年科技中心", 22620, 5),
    "62b945cd9aebef53937fecc6": Department("企业创新服务中心", 20000, 6),
    "62b945cd9aebef53937fecc7": Department("农村专业技术服务中心", 10000, 7),
    "62b945cd9aebef53937fecc8": Department("中国国际科技交流中心", 3200, 8),
    "62b945cd9aebef53937fecc9": Department("科学技术传播中心", 800, 9),
    "62b945cd9aebef53937fecca": Department("培训和人才服务中心", 5000, 10),
    "62b945cd9aebef53937feccb": Department("科技导报社", 8000, 11)
}


@app.command()
def task_update_okr(year: int = typer.Option(..., help="更新年考核目标")):
    """okr 目标考核"""

    year = year if year else datetime.utcnow().year

    for k, v in constraint_dept.items():
        col_okr.update_one({"year": year, "dept_id": k},
                           {"$set": {"dept_id": k, "dept_label": v.label, "okr": v.target, "order": v.order,
                                     "year": year, "update_at": datetime.utcnow()}},
                           upsert=True)

    print("end...")


if __name__ == '__main__':
    app()
